﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;


namespace CMS.BLL
{
    public class BasketDetail
    {
          #region Common
        public eBasketDetail   Data;

        public BasketDetail()
        {
            Data = new eBasketDetail();
		}

        ~BasketDetail()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cBasketDetail objDAL = new cBasketDetail();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cBasketDetail objDAL = new cBasketDetail();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cBasketDetail objInfor = new cBasketDetail(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = 1;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cBasketDetail objInfor = new cBasketDetail();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

       

        private void MappingData(cBasketDetail objInfor)
        {
            objInfor.ProductID = Data.ProductID;
            objInfor.Price = Data.Price;
            objInfor.Quantity = Data.Quantity;
            objInfor.BasketID = Data.BasketID; 
        }

        private void ConvertData(cBasketDetail objInfor)
        {
            Data.ProductID =objInfor.ProductID ;
            Data.Price =objInfor.Price  ;
            Data.Quantity =objInfor.Quantity ;
            Data.BasketID  =objInfor.BasketID ; 
        }
        #endregion

        public DataTable Search(int BasketID)
        {
            DataTable tbResult = new DataTable();
            cBasketDetail objDAL = new cBasketDetail();
            tbResult = objDAL.Search(BasketID);
            return tbResult;
        }

    }
}
